/**
 * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.crossriver.crgis.database.service.persistence;

import com.crossriver.crgis.database.NoSuchBank_Payment_SlipException;
import com.crossriver.crgis.database.model.Bank_Payment_Slip;
import com.crossriver.crgis.database.model.impl.Bank_Payment_SlipImpl;
import com.crossriver.crgis.database.model.impl.Bank_Payment_SlipModelImpl;

import com.liferay.portal.NoSuchModelException;
import com.liferay.portal.kernel.annotation.BeanReference;
import com.liferay.portal.kernel.cache.CacheRegistryUtil;
import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderPath;
import com.liferay.portal.kernel.dao.orm.Query;
import com.liferay.portal.kernel.dao.orm.QueryPos;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.dao.orm.Session;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.InstanceFactory;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.model.ModelListener;
import com.liferay.portal.service.persistence.BatchSessionUtil;
import com.liferay.portal.service.persistence.ResourcePersistence;
import com.liferay.portal.service.persistence.UserPersistence;
import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;

import java.io.Serializable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * The persistence implementation for the bank_ payment_ slip service.
 *
 * <p>
 * Never modify or reference this class directly. Always use {@link Bank_Payment_SlipUtil} to access the bank_ payment_ slip persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
 * </p>
 *
 * <p>
 * Caching information and settings can be found in <code>portal.properties</code>
 * </p>
 *
 * @author Wole Adetiba
 * @see Bank_Payment_SlipPersistence
 * @see Bank_Payment_SlipUtil
 * @generated
 */
public class Bank_Payment_SlipPersistenceImpl extends BasePersistenceImpl<Bank_Payment_Slip>
	implements Bank_Payment_SlipPersistence {
	public static final String FINDER_CLASS_NAME_ENTITY = Bank_Payment_SlipImpl.class.getName();
	public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
		".List";
	public static final FinderPath FINDER_PATH_FIND_BY_APPLICATIONID = new FinderPath(Bank_Payment_SlipModelImpl.ENTITY_CACHE_ENABLED,
			Bank_Payment_SlipModelImpl.FINDER_CACHE_ENABLED,
			FINDER_CLASS_NAME_LIST, "findByApplicationId",
			new String[] {
				String.class.getName(),
				
			"java.lang.Integer", "java.lang.Integer",
				"com.liferay.portal.kernel.util.OrderByComparator"
			});
	public static final FinderPath FINDER_PATH_COUNT_BY_APPLICATIONID = new FinderPath(Bank_Payment_SlipModelImpl.ENTITY_CACHE_ENABLED,
			Bank_Payment_SlipModelImpl.FINDER_CACHE_ENABLED,
			FINDER_CLASS_NAME_LIST, "countByApplicationId",
			new String[] { String.class.getName() });
	public static final FinderPath FINDER_PATH_FIND_BY_USERID = new FinderPath(Bank_Payment_SlipModelImpl.ENTITY_CACHE_ENABLED,
			Bank_Payment_SlipModelImpl.FINDER_CACHE_ENABLED,
			FINDER_CLASS_NAME_LIST, "findByUserId",
			new String[] {
				String.class.getName(),
				
			"java.lang.Integer", "java.lang.Integer",
				"com.liferay.portal.kernel.util.OrderByComparator"
			});
	public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(Bank_Payment_SlipModelImpl.ENTITY_CACHE_ENABLED,
			Bank_Payment_SlipModelImpl.FINDER_CACHE_ENABLED,
			FINDER_CLASS_NAME_LIST, "countByUserId",
			new String[] { String.class.getName() });
	public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(Bank_Payment_SlipModelImpl.ENTITY_CACHE_ENABLED,
			Bank_Payment_SlipModelImpl.FINDER_CACHE_ENABLED,
			FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
	public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(Bank_Payment_SlipModelImpl.ENTITY_CACHE_ENABLED,
			Bank_Payment_SlipModelImpl.FINDER_CACHE_ENABLED,
			FINDER_CLASS_NAME_LIST, "countAll", new String[0]);

	/**
	 * Caches the bank_ payment_ slip in the entity cache if it is enabled.
	 *
	 * @param bank_Payment_Slip the bank_ payment_ slip to cache
	 */
	public void cacheResult(Bank_Payment_Slip bank_Payment_Slip) {
		EntityCacheUtil.putResult(Bank_Payment_SlipModelImpl.ENTITY_CACHE_ENABLED,
			Bank_Payment_SlipImpl.class, bank_Payment_Slip.getPrimaryKey(),
			bank_Payment_Slip);
	}

	/**
	 * Caches the bank_ payment_ slips in the entity cache if it is enabled.
	 *
	 * @param bank_Payment_Slips the bank_ payment_ slips to cache
	 */
	public void cacheResult(List<Bank_Payment_Slip> bank_Payment_Slips) {
		for (Bank_Payment_Slip bank_Payment_Slip : bank_Payment_Slips) {
			if (EntityCacheUtil.getResult(
						Bank_Payment_SlipModelImpl.ENTITY_CACHE_ENABLED,
						Bank_Payment_SlipImpl.class,
						bank_Payment_Slip.getPrimaryKey(), this) == null) {
				cacheResult(bank_Payment_Slip);
			}
		}
	}

	/**
	 * Clears the cache for all bank_ payment_ slips.
	 *
	 * <p>
	 * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
	 * </p>
	 */
	public void clearCache() {
		CacheRegistryUtil.clear(Bank_Payment_SlipImpl.class.getName());
		EntityCacheUtil.clearCache(Bank_Payment_SlipImpl.class.getName());
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
	}

	/**
	 * Clears the cache for the bank_ payment_ slip.
	 *
	 * <p>
	 * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
	 * </p>
	 */
	public void clearCache(Bank_Payment_Slip bank_Payment_Slip) {
		EntityCacheUtil.removeResult(Bank_Payment_SlipModelImpl.ENTITY_CACHE_ENABLED,
			Bank_Payment_SlipImpl.class, bank_Payment_Slip.getPrimaryKey());
	}

	/**
	 * Creates a new bank_ payment_ slip with the primary key. Does not add the bank_ payment_ slip to the database.
	 *
	 * @param depSlipNo the primary key for the new bank_ payment_ slip
	 * @return the new bank_ payment_ slip
	 */
	public Bank_Payment_Slip create(String depSlipNo) {
		Bank_Payment_Slip bank_Payment_Slip = new Bank_Payment_SlipImpl();

		bank_Payment_Slip.setNew(true);
		bank_Payment_Slip.setPrimaryKey(depSlipNo);

		return bank_Payment_Slip;
	}

	/**
	 * Removes the bank_ payment_ slip with the primary key from the database. Also notifies the appropriate model listeners.
	 *
	 * @param primaryKey the primary key of the bank_ payment_ slip to remove
	 * @return the bank_ payment_ slip that was removed
	 * @throws com.liferay.portal.NoSuchModelException if a bank_ payment_ slip with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Bank_Payment_Slip remove(Serializable primaryKey)
		throws NoSuchModelException, SystemException {
		return remove((String)primaryKey);
	}

	/**
	 * Removes the bank_ payment_ slip with the primary key from the database. Also notifies the appropriate model listeners.
	 *
	 * @param depSlipNo the primary key of the bank_ payment_ slip to remove
	 * @return the bank_ payment_ slip that was removed
	 * @throws com.crossriver.crgis.database.NoSuchBank_Payment_SlipException if a bank_ payment_ slip with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Bank_Payment_Slip remove(String depSlipNo)
		throws NoSuchBank_Payment_SlipException, SystemException {
		Session session = null;

		try {
			session = openSession();

			Bank_Payment_Slip bank_Payment_Slip = (Bank_Payment_Slip)session.get(Bank_Payment_SlipImpl.class,
					depSlipNo);

			if (bank_Payment_Slip == null) {
				if (_log.isWarnEnabled()) {
					_log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + depSlipNo);
				}

				throw new NoSuchBank_Payment_SlipException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
					depSlipNo);
			}

			return remove(bank_Payment_Slip);
		}
		catch (NoSuchBank_Payment_SlipException nsee) {
			throw nsee;
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}
	}

	protected Bank_Payment_Slip removeImpl(Bank_Payment_Slip bank_Payment_Slip)
		throws SystemException {
		bank_Payment_Slip = toUnwrappedModel(bank_Payment_Slip);

		Session session = null;

		try {
			session = openSession();

			BatchSessionUtil.delete(session, bank_Payment_Slip);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}

		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);

		EntityCacheUtil.removeResult(Bank_Payment_SlipModelImpl.ENTITY_CACHE_ENABLED,
			Bank_Payment_SlipImpl.class, bank_Payment_Slip.getPrimaryKey());

		return bank_Payment_Slip;
	}

	public Bank_Payment_Slip updateImpl(
		com.crossriver.crgis.database.model.Bank_Payment_Slip bank_Payment_Slip,
		boolean merge) throws SystemException {
		bank_Payment_Slip = toUnwrappedModel(bank_Payment_Slip);

		Session session = null;

		try {
			session = openSession();

			BatchSessionUtil.update(session, bank_Payment_Slip, merge);

			bank_Payment_Slip.setNew(false);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}

		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);

		EntityCacheUtil.putResult(Bank_Payment_SlipModelImpl.ENTITY_CACHE_ENABLED,
			Bank_Payment_SlipImpl.class, bank_Payment_Slip.getPrimaryKey(),
			bank_Payment_Slip);

		return bank_Payment_Slip;
	}

	protected Bank_Payment_Slip toUnwrappedModel(
		Bank_Payment_Slip bank_Payment_Slip) {
		if (bank_Payment_Slip instanceof Bank_Payment_SlipImpl) {
			return bank_Payment_Slip;
		}

		Bank_Payment_SlipImpl bank_Payment_SlipImpl = new Bank_Payment_SlipImpl();

		bank_Payment_SlipImpl.setNew(bank_Payment_Slip.isNew());
		bank_Payment_SlipImpl.setPrimaryKey(bank_Payment_Slip.getPrimaryKey());

		bank_Payment_SlipImpl.setDepSlipNo(bank_Payment_Slip.getDepSlipNo());
		bank_Payment_SlipImpl.setUserId(bank_Payment_Slip.getUserId());
		bank_Payment_SlipImpl.setRegistedDate(bank_Payment_Slip.getRegistedDate());
		bank_Payment_SlipImpl.setApplicationId(bank_Payment_Slip.getApplicationId());
		bank_Payment_SlipImpl.setDepositorName(bank_Payment_Slip.getDepositorName());
		bank_Payment_SlipImpl.setPaidAmount(bank_Payment_Slip.getPaidAmount());
		bank_Payment_SlipImpl.setApprovedAmount(bank_Payment_Slip.getApprovedAmount());
		bank_Payment_SlipImpl.setBankName(bank_Payment_Slip.getBankName());
		bank_Payment_SlipImpl.setUploadDepositSlip(bank_Payment_Slip.getUploadDepositSlip());
		bank_Payment_SlipImpl.setUploadDepositSlipFilename(bank_Payment_Slip.getUploadDepositSlipFilename());
		bank_Payment_SlipImpl.setUploadDepositSlipDocName(bank_Payment_Slip.getUploadDepositSlipDocName());
		bank_Payment_SlipImpl.setStatus(bank_Payment_Slip.getStatus());

		return bank_Payment_SlipImpl;
	}

	/**
	 * Finds the bank_ payment_ slip with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
	 *
	 * @param primaryKey the primary key of the bank_ payment_ slip to find
	 * @return the bank_ payment_ slip
	 * @throws com.liferay.portal.NoSuchModelException if a bank_ payment_ slip with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Bank_Payment_Slip findByPrimaryKey(Serializable primaryKey)
		throws NoSuchModelException, SystemException {
		return findByPrimaryKey((String)primaryKey);
	}

	/**
	 * Finds the bank_ payment_ slip with the primary key or throws a {@link com.crossriver.crgis.database.NoSuchBank_Payment_SlipException} if it could not be found.
	 *
	 * @param depSlipNo the primary key of the bank_ payment_ slip to find
	 * @return the bank_ payment_ slip
	 * @throws com.crossriver.crgis.database.NoSuchBank_Payment_SlipException if a bank_ payment_ slip with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Bank_Payment_Slip findByPrimaryKey(String depSlipNo)
		throws NoSuchBank_Payment_SlipException, SystemException {
		Bank_Payment_Slip bank_Payment_Slip = fetchByPrimaryKey(depSlipNo);

		if (bank_Payment_Slip == null) {
			if (_log.isWarnEnabled()) {
				_log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + depSlipNo);
			}

			throw new NoSuchBank_Payment_SlipException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
				depSlipNo);
		}

		return bank_Payment_Slip;
	}

	/**
	 * Finds the bank_ payment_ slip with the primary key or returns <code>null</code> if it could not be found.
	 *
	 * @param primaryKey the primary key of the bank_ payment_ slip to find
	 * @return the bank_ payment_ slip, or <code>null</code> if a bank_ payment_ slip with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Bank_Payment_Slip fetchByPrimaryKey(Serializable primaryKey)
		throws SystemException {
		return fetchByPrimaryKey((String)primaryKey);
	}

	/**
	 * Finds the bank_ payment_ slip with the primary key or returns <code>null</code> if it could not be found.
	 *
	 * @param depSlipNo the primary key of the bank_ payment_ slip to find
	 * @return the bank_ payment_ slip, or <code>null</code> if a bank_ payment_ slip with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Bank_Payment_Slip fetchByPrimaryKey(String depSlipNo)
		throws SystemException {
		Bank_Payment_Slip bank_Payment_Slip = (Bank_Payment_Slip)EntityCacheUtil.getResult(Bank_Payment_SlipModelImpl.ENTITY_CACHE_ENABLED,
				Bank_Payment_SlipImpl.class, depSlipNo, this);

		if (bank_Payment_Slip == null) {
			Session session = null;

			try {
				session = openSession();

				bank_Payment_Slip = (Bank_Payment_Slip)session.get(Bank_Payment_SlipImpl.class,
						depSlipNo);
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (bank_Payment_Slip != null) {
					cacheResult(bank_Payment_Slip);
				}

				closeSession(session);
			}
		}

		return bank_Payment_Slip;
	}

	/**
	 * Finds all the bank_ payment_ slips where applicationId = &#63;.
	 *
	 * @param applicationId the application id to search with
	 * @return the matching bank_ payment_ slips
	 * @throws SystemException if a system exception occurred
	 */
	public List<Bank_Payment_Slip> findByApplicationId(String applicationId)
		throws SystemException {
		return findByApplicationId(applicationId, QueryUtil.ALL_POS,
			QueryUtil.ALL_POS, null);
	}

	/**
	 * Finds a range of all the bank_ payment_ slips where applicationId = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param applicationId the application id to search with
	 * @param start the lower bound of the range of bank_ payment_ slips to return
	 * @param end the upper bound of the range of bank_ payment_ slips to return (not inclusive)
	 * @return the range of matching bank_ payment_ slips
	 * @throws SystemException if a system exception occurred
	 */
	public List<Bank_Payment_Slip> findByApplicationId(String applicationId,
		int start, int end) throws SystemException {
		return findByApplicationId(applicationId, start, end, null);
	}

	/**
	 * Finds an ordered range of all the bank_ payment_ slips where applicationId = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param applicationId the application id to search with
	 * @param start the lower bound of the range of bank_ payment_ slips to return
	 * @param end the upper bound of the range of bank_ payment_ slips to return (not inclusive)
	 * @param orderByComparator the comparator to order the results by
	 * @return the ordered range of matching bank_ payment_ slips
	 * @throws SystemException if a system exception occurred
	 */
	public List<Bank_Payment_Slip> findByApplicationId(String applicationId,
		int start, int end, OrderByComparator orderByComparator)
		throws SystemException {
		Object[] finderArgs = new Object[] {
				applicationId,
				
				String.valueOf(start), String.valueOf(end),
				String.valueOf(orderByComparator)
			};

		List<Bank_Payment_Slip> list = (List<Bank_Payment_Slip>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_APPLICATIONID,
				finderArgs, this);

		if (list == null) {
			StringBundler query = null;

			if (orderByComparator != null) {
				query = new StringBundler(3 +
						(orderByComparator.getOrderByFields().length * 3));
			}
			else {
				query = new StringBundler(3);
			}

			query.append(_SQL_SELECT_BANK_PAYMENT_SLIP_WHERE);

			if (applicationId == null) {
				query.append(_FINDER_COLUMN_APPLICATIONID_APPLICATIONID_1);
			}
			else {
				if (applicationId.equals(StringPool.BLANK)) {
					query.append(_FINDER_COLUMN_APPLICATIONID_APPLICATIONID_3);
				}
				else {
					query.append(_FINDER_COLUMN_APPLICATIONID_APPLICATIONID_2);
				}
			}

			if (orderByComparator != null) {
				appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
					orderByComparator);
			}

			else {
				query.append(Bank_Payment_SlipModelImpl.ORDER_BY_JPQL);
			}

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				if (applicationId != null) {
					qPos.add(applicationId);
				}

				list = (List<Bank_Payment_Slip>)QueryUtil.list(q, getDialect(),
						start, end);
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (list == null) {
					FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_APPLICATIONID,
						finderArgs);
				}
				else {
					cacheResult(list);

					FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_APPLICATIONID,
						finderArgs, list);
				}

				closeSession(session);
			}
		}

		return list;
	}

	/**
	 * Finds the first bank_ payment_ slip in the ordered set where applicationId = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param applicationId the application id to search with
	 * @param orderByComparator the comparator to order the set by
	 * @return the first matching bank_ payment_ slip
	 * @throws com.crossriver.crgis.database.NoSuchBank_Payment_SlipException if a matching bank_ payment_ slip could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Bank_Payment_Slip findByApplicationId_First(String applicationId,
		OrderByComparator orderByComparator)
		throws NoSuchBank_Payment_SlipException, SystemException {
		List<Bank_Payment_Slip> list = findByApplicationId(applicationId, 0, 1,
				orderByComparator);

		if (list.isEmpty()) {
			StringBundler msg = new StringBundler(4);

			msg.append(_NO_SUCH_ENTITY_WITH_KEY);

			msg.append("applicationId=");
			msg.append(applicationId);

			msg.append(StringPool.CLOSE_CURLY_BRACE);

			throw new NoSuchBank_Payment_SlipException(msg.toString());
		}
		else {
			return list.get(0);
		}
	}

	/**
	 * Finds the last bank_ payment_ slip in the ordered set where applicationId = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param applicationId the application id to search with
	 * @param orderByComparator the comparator to order the set by
	 * @return the last matching bank_ payment_ slip
	 * @throws com.crossriver.crgis.database.NoSuchBank_Payment_SlipException if a matching bank_ payment_ slip could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Bank_Payment_Slip findByApplicationId_Last(String applicationId,
		OrderByComparator orderByComparator)
		throws NoSuchBank_Payment_SlipException, SystemException {
		int count = countByApplicationId(applicationId);

		List<Bank_Payment_Slip> list = findByApplicationId(applicationId,
				count - 1, count, orderByComparator);

		if (list.isEmpty()) {
			StringBundler msg = new StringBundler(4);

			msg.append(_NO_SUCH_ENTITY_WITH_KEY);

			msg.append("applicationId=");
			msg.append(applicationId);

			msg.append(StringPool.CLOSE_CURLY_BRACE);

			throw new NoSuchBank_Payment_SlipException(msg.toString());
		}
		else {
			return list.get(0);
		}
	}

	/**
	 * Finds the bank_ payment_ slips before and after the current bank_ payment_ slip in the ordered set where applicationId = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param depSlipNo the primary key of the current bank_ payment_ slip
	 * @param applicationId the application id to search with
	 * @param orderByComparator the comparator to order the set by
	 * @return the previous, current, and next bank_ payment_ slip
	 * @throws com.crossriver.crgis.database.NoSuchBank_Payment_SlipException if a bank_ payment_ slip with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Bank_Payment_Slip[] findByApplicationId_PrevAndNext(
		String depSlipNo, String applicationId,
		OrderByComparator orderByComparator)
		throws NoSuchBank_Payment_SlipException, SystemException {
		Bank_Payment_Slip bank_Payment_Slip = findByPrimaryKey(depSlipNo);

		Session session = null;

		try {
			session = openSession();

			Bank_Payment_Slip[] array = new Bank_Payment_SlipImpl[3];

			array[0] = getByApplicationId_PrevAndNext(session,
					bank_Payment_Slip, applicationId, orderByComparator, true);

			array[1] = bank_Payment_Slip;

			array[2] = getByApplicationId_PrevAndNext(session,
					bank_Payment_Slip, applicationId, orderByComparator, false);

			return array;
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}
	}

	protected Bank_Payment_Slip getByApplicationId_PrevAndNext(
		Session session, Bank_Payment_Slip bank_Payment_Slip,
		String applicationId, OrderByComparator orderByComparator,
		boolean previous) {
		StringBundler query = null;

		if (orderByComparator != null) {
			query = new StringBundler(6 +
					(orderByComparator.getOrderByFields().length * 6));
		}
		else {
			query = new StringBundler(3);
		}

		query.append(_SQL_SELECT_BANK_PAYMENT_SLIP_WHERE);

		if (applicationId == null) {
			query.append(_FINDER_COLUMN_APPLICATIONID_APPLICATIONID_1);
		}
		else {
			if (applicationId.equals(StringPool.BLANK)) {
				query.append(_FINDER_COLUMN_APPLICATIONID_APPLICATIONID_3);
			}
			else {
				query.append(_FINDER_COLUMN_APPLICATIONID_APPLICATIONID_2);
			}
		}

		if (orderByComparator != null) {
			String[] orderByFields = orderByComparator.getOrderByFields();

			if (orderByFields.length > 0) {
				query.append(WHERE_AND);
			}

			for (int i = 0; i < orderByFields.length; i++) {
				query.append(_ORDER_BY_ENTITY_ALIAS);
				query.append(orderByFields[i]);

				if ((i + 1) < orderByFields.length) {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(WHERE_GREATER_THAN_HAS_NEXT);
					}
					else {
						query.append(WHERE_LESSER_THAN_HAS_NEXT);
					}
				}
				else {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(WHERE_GREATER_THAN);
					}
					else {
						query.append(WHERE_LESSER_THAN);
					}
				}
			}

			query.append(ORDER_BY_CLAUSE);

			for (int i = 0; i < orderByFields.length; i++) {
				query.append(_ORDER_BY_ENTITY_ALIAS);
				query.append(orderByFields[i]);

				if ((i + 1) < orderByFields.length) {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(ORDER_BY_ASC_HAS_NEXT);
					}
					else {
						query.append(ORDER_BY_DESC_HAS_NEXT);
					}
				}
				else {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(ORDER_BY_ASC);
					}
					else {
						query.append(ORDER_BY_DESC);
					}
				}
			}
		}

		else {
			query.append(Bank_Payment_SlipModelImpl.ORDER_BY_JPQL);
		}

		String sql = query.toString();

		Query q = session.createQuery(sql);

		q.setFirstResult(0);
		q.setMaxResults(2);

		QueryPos qPos = QueryPos.getInstance(q);

		if (applicationId != null) {
			qPos.add(applicationId);
		}

		if (orderByComparator != null) {
			Object[] values = orderByComparator.getOrderByValues(bank_Payment_Slip);

			for (Object value : values) {
				qPos.add(value);
			}
		}

		List<Bank_Payment_Slip> list = q.list();

		if (list.size() == 2) {
			return list.get(1);
		}
		else {
			return null;
		}
	}

	/**
	 * Finds all the bank_ payment_ slips where userId = &#63;.
	 *
	 * @param userId the user id to search with
	 * @return the matching bank_ payment_ slips
	 * @throws SystemException if a system exception occurred
	 */
	public List<Bank_Payment_Slip> findByUserId(String userId)
		throws SystemException {
		return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
	}

	/**
	 * Finds a range of all the bank_ payment_ slips where userId = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param userId the user id to search with
	 * @param start the lower bound of the range of bank_ payment_ slips to return
	 * @param end the upper bound of the range of bank_ payment_ slips to return (not inclusive)
	 * @return the range of matching bank_ payment_ slips
	 * @throws SystemException if a system exception occurred
	 */
	public List<Bank_Payment_Slip> findByUserId(String userId, int start,
		int end) throws SystemException {
		return findByUserId(userId, start, end, null);
	}

	/**
	 * Finds an ordered range of all the bank_ payment_ slips where userId = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param userId the user id to search with
	 * @param start the lower bound of the range of bank_ payment_ slips to return
	 * @param end the upper bound of the range of bank_ payment_ slips to return (not inclusive)
	 * @param orderByComparator the comparator to order the results by
	 * @return the ordered range of matching bank_ payment_ slips
	 * @throws SystemException if a system exception occurred
	 */
	public List<Bank_Payment_Slip> findByUserId(String userId, int start,
		int end, OrderByComparator orderByComparator) throws SystemException {
		Object[] finderArgs = new Object[] {
				userId,
				
				String.valueOf(start), String.valueOf(end),
				String.valueOf(orderByComparator)
			};

		List<Bank_Payment_Slip> list = (List<Bank_Payment_Slip>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
				finderArgs, this);

		if (list == null) {
			StringBundler query = null;

			if (orderByComparator != null) {
				query = new StringBundler(3 +
						(orderByComparator.getOrderByFields().length * 3));
			}
			else {
				query = new StringBundler(3);
			}

			query.append(_SQL_SELECT_BANK_PAYMENT_SLIP_WHERE);

			if (userId == null) {
				query.append(_FINDER_COLUMN_USERID_USERID_1);
			}
			else {
				if (userId.equals(StringPool.BLANK)) {
					query.append(_FINDER_COLUMN_USERID_USERID_3);
				}
				else {
					query.append(_FINDER_COLUMN_USERID_USERID_2);
				}
			}

			if (orderByComparator != null) {
				appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
					orderByComparator);
			}

			else {
				query.append(Bank_Payment_SlipModelImpl.ORDER_BY_JPQL);
			}

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				if (userId != null) {
					qPos.add(userId);
				}

				list = (List<Bank_Payment_Slip>)QueryUtil.list(q, getDialect(),
						start, end);
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (list == null) {
					FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_USERID,
						finderArgs);
				}
				else {
					cacheResult(list);

					FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
						finderArgs, list);
				}

				closeSession(session);
			}
		}

		return list;
	}

	/**
	 * Finds the first bank_ payment_ slip in the ordered set where userId = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param userId the user id to search with
	 * @param orderByComparator the comparator to order the set by
	 * @return the first matching bank_ payment_ slip
	 * @throws com.crossriver.crgis.database.NoSuchBank_Payment_SlipException if a matching bank_ payment_ slip could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Bank_Payment_Slip findByUserId_First(String userId,
		OrderByComparator orderByComparator)
		throws NoSuchBank_Payment_SlipException, SystemException {
		List<Bank_Payment_Slip> list = findByUserId(userId, 0, 1,
				orderByComparator);

		if (list.isEmpty()) {
			StringBundler msg = new StringBundler(4);

			msg.append(_NO_SUCH_ENTITY_WITH_KEY);

			msg.append("userId=");
			msg.append(userId);

			msg.append(StringPool.CLOSE_CURLY_BRACE);

			throw new NoSuchBank_Payment_SlipException(msg.toString());
		}
		else {
			return list.get(0);
		}
	}

	/**
	 * Finds the last bank_ payment_ slip in the ordered set where userId = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param userId the user id to search with
	 * @param orderByComparator the comparator to order the set by
	 * @return the last matching bank_ payment_ slip
	 * @throws com.crossriver.crgis.database.NoSuchBank_Payment_SlipException if a matching bank_ payment_ slip could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Bank_Payment_Slip findByUserId_Last(String userId,
		OrderByComparator orderByComparator)
		throws NoSuchBank_Payment_SlipException, SystemException {
		int count = countByUserId(userId);

		List<Bank_Payment_Slip> list = findByUserId(userId, count - 1, count,
				orderByComparator);

		if (list.isEmpty()) {
			StringBundler msg = new StringBundler(4);

			msg.append(_NO_SUCH_ENTITY_WITH_KEY);

			msg.append("userId=");
			msg.append(userId);

			msg.append(StringPool.CLOSE_CURLY_BRACE);

			throw new NoSuchBank_Payment_SlipException(msg.toString());
		}
		else {
			return list.get(0);
		}
	}

	/**
	 * Finds the bank_ payment_ slips before and after the current bank_ payment_ slip in the ordered set where userId = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param depSlipNo the primary key of the current bank_ payment_ slip
	 * @param userId the user id to search with
	 * @param orderByComparator the comparator to order the set by
	 * @return the previous, current, and next bank_ payment_ slip
	 * @throws com.crossriver.crgis.database.NoSuchBank_Payment_SlipException if a bank_ payment_ slip with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Bank_Payment_Slip[] findByUserId_PrevAndNext(String depSlipNo,
		String userId, OrderByComparator orderByComparator)
		throws NoSuchBank_Payment_SlipException, SystemException {
		Bank_Payment_Slip bank_Payment_Slip = findByPrimaryKey(depSlipNo);

		Session session = null;

		try {
			session = openSession();

			Bank_Payment_Slip[] array = new Bank_Payment_SlipImpl[3];

			array[0] = getByUserId_PrevAndNext(session, bank_Payment_Slip,
					userId, orderByComparator, true);

			array[1] = bank_Payment_Slip;

			array[2] = getByUserId_PrevAndNext(session, bank_Payment_Slip,
					userId, orderByComparator, false);

			return array;
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}
	}

	protected Bank_Payment_Slip getByUserId_PrevAndNext(Session session,
		Bank_Payment_Slip bank_Payment_Slip, String userId,
		OrderByComparator orderByComparator, boolean previous) {
		StringBundler query = null;

		if (orderByComparator != null) {
			query = new StringBundler(6 +
					(orderByComparator.getOrderByFields().length * 6));
		}
		else {
			query = new StringBundler(3);
		}

		query.append(_SQL_SELECT_BANK_PAYMENT_SLIP_WHERE);

		if (userId == null) {
			query.append(_FINDER_COLUMN_USERID_USERID_1);
		}
		else {
			if (userId.equals(StringPool.BLANK)) {
				query.append(_FINDER_COLUMN_USERID_USERID_3);
			}
			else {
				query.append(_FINDER_COLUMN_USERID_USERID_2);
			}
		}

		if (orderByComparator != null) {
			String[] orderByFields = orderByComparator.getOrderByFields();

			if (orderByFields.length > 0) {
				query.append(WHERE_AND);
			}

			for (int i = 0; i < orderByFields.length; i++) {
				query.append(_ORDER_BY_ENTITY_ALIAS);
				query.append(orderByFields[i]);

				if ((i + 1) < orderByFields.length) {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(WHERE_GREATER_THAN_HAS_NEXT);
					}
					else {
						query.append(WHERE_LESSER_THAN_HAS_NEXT);
					}
				}
				else {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(WHERE_GREATER_THAN);
					}
					else {
						query.append(WHERE_LESSER_THAN);
					}
				}
			}

			query.append(ORDER_BY_CLAUSE);

			for (int i = 0; i < orderByFields.length; i++) {
				query.append(_ORDER_BY_ENTITY_ALIAS);
				query.append(orderByFields[i]);

				if ((i + 1) < orderByFields.length) {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(ORDER_BY_ASC_HAS_NEXT);
					}
					else {
						query.append(ORDER_BY_DESC_HAS_NEXT);
					}
				}
				else {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(ORDER_BY_ASC);
					}
					else {
						query.append(ORDER_BY_DESC);
					}
				}
			}
		}

		else {
			query.append(Bank_Payment_SlipModelImpl.ORDER_BY_JPQL);
		}

		String sql = query.toString();

		Query q = session.createQuery(sql);

		q.setFirstResult(0);
		q.setMaxResults(2);

		QueryPos qPos = QueryPos.getInstance(q);

		if (userId != null) {
			qPos.add(userId);
		}

		if (orderByComparator != null) {
			Object[] values = orderByComparator.getOrderByValues(bank_Payment_Slip);

			for (Object value : values) {
				qPos.add(value);
			}
		}

		List<Bank_Payment_Slip> list = q.list();

		if (list.size() == 2) {
			return list.get(1);
		}
		else {
			return null;
		}
	}

	/**
	 * Finds all the bank_ payment_ slips.
	 *
	 * @return the bank_ payment_ slips
	 * @throws SystemException if a system exception occurred
	 */
	public List<Bank_Payment_Slip> findAll() throws SystemException {
		return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
	}

	/**
	 * Finds a range of all the bank_ payment_ slips.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param start the lower bound of the range of bank_ payment_ slips to return
	 * @param end the upper bound of the range of bank_ payment_ slips to return (not inclusive)
	 * @return the range of bank_ payment_ slips
	 * @throws SystemException if a system exception occurred
	 */
	public List<Bank_Payment_Slip> findAll(int start, int end)
		throws SystemException {
		return findAll(start, end, null);
	}

	/**
	 * Finds an ordered range of all the bank_ payment_ slips.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param start the lower bound of the range of bank_ payment_ slips to return
	 * @param end the upper bound of the range of bank_ payment_ slips to return (not inclusive)
	 * @param orderByComparator the comparator to order the results by
	 * @return the ordered range of bank_ payment_ slips
	 * @throws SystemException if a system exception occurred
	 */
	public List<Bank_Payment_Slip> findAll(int start, int end,
		OrderByComparator orderByComparator) throws SystemException {
		Object[] finderArgs = new Object[] {
				String.valueOf(start), String.valueOf(end),
				String.valueOf(orderByComparator)
			};

		List<Bank_Payment_Slip> list = (List<Bank_Payment_Slip>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
				finderArgs, this);

		if (list == null) {
			StringBundler query = null;
			String sql = null;

			if (orderByComparator != null) {
				query = new StringBundler(2 +
						(orderByComparator.getOrderByFields().length * 3));

				query.append(_SQL_SELECT_BANK_PAYMENT_SLIP);

				appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
					orderByComparator);

				sql = query.toString();
			}
			else {
				sql = _SQL_SELECT_BANK_PAYMENT_SLIP.concat(Bank_Payment_SlipModelImpl.ORDER_BY_JPQL);
			}

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				if (orderByComparator == null) {
					list = (List<Bank_Payment_Slip>)QueryUtil.list(q,
							getDialect(), start, end, false);

					Collections.sort(list);
				}
				else {
					list = (List<Bank_Payment_Slip>)QueryUtil.list(q,
							getDialect(), start, end);
				}
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (list == null) {
					FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL,
						finderArgs);
				}
				else {
					cacheResult(list);

					FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs,
						list);
				}

				closeSession(session);
			}
		}

		return list;
	}

	/**
	 * Removes all the bank_ payment_ slips where applicationId = &#63; from the database.
	 *
	 * @param applicationId the application id to search with
	 * @throws SystemException if a system exception occurred
	 */
	public void removeByApplicationId(String applicationId)
		throws SystemException {
		for (Bank_Payment_Slip bank_Payment_Slip : findByApplicationId(
				applicationId)) {
			remove(bank_Payment_Slip);
		}
	}

	/**
	 * Removes all the bank_ payment_ slips where userId = &#63; from the database.
	 *
	 * @param userId the user id to search with
	 * @throws SystemException if a system exception occurred
	 */
	public void removeByUserId(String userId) throws SystemException {
		for (Bank_Payment_Slip bank_Payment_Slip : findByUserId(userId)) {
			remove(bank_Payment_Slip);
		}
	}

	/**
	 * Removes all the bank_ payment_ slips from the database.
	 *
	 * @throws SystemException if a system exception occurred
	 */
	public void removeAll() throws SystemException {
		for (Bank_Payment_Slip bank_Payment_Slip : findAll()) {
			remove(bank_Payment_Slip);
		}
	}

	/**
	 * Counts all the bank_ payment_ slips where applicationId = &#63;.
	 *
	 * @param applicationId the application id to search with
	 * @return the number of matching bank_ payment_ slips
	 * @throws SystemException if a system exception occurred
	 */
	public int countByApplicationId(String applicationId)
		throws SystemException {
		Object[] finderArgs = new Object[] { applicationId };

		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_APPLICATIONID,
				finderArgs, this);

		if (count == null) {
			StringBundler query = new StringBundler(2);

			query.append(_SQL_COUNT_BANK_PAYMENT_SLIP_WHERE);

			if (applicationId == null) {
				query.append(_FINDER_COLUMN_APPLICATIONID_APPLICATIONID_1);
			}
			else {
				if (applicationId.equals(StringPool.BLANK)) {
					query.append(_FINDER_COLUMN_APPLICATIONID_APPLICATIONID_3);
				}
				else {
					query.append(_FINDER_COLUMN_APPLICATIONID_APPLICATIONID_2);
				}
			}

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				if (applicationId != null) {
					qPos.add(applicationId);
				}

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_APPLICATIONID,
					finderArgs, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Counts all the bank_ payment_ slips where userId = &#63;.
	 *
	 * @param userId the user id to search with
	 * @return the number of matching bank_ payment_ slips
	 * @throws SystemException if a system exception occurred
	 */
	public int countByUserId(String userId) throws SystemException {
		Object[] finderArgs = new Object[] { userId };

		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
				finderArgs, this);

		if (count == null) {
			StringBundler query = new StringBundler(2);

			query.append(_SQL_COUNT_BANK_PAYMENT_SLIP_WHERE);

			if (userId == null) {
				query.append(_FINDER_COLUMN_USERID_USERID_1);
			}
			else {
				if (userId.equals(StringPool.BLANK)) {
					query.append(_FINDER_COLUMN_USERID_USERID_3);
				}
				else {
					query.append(_FINDER_COLUMN_USERID_USERID_2);
				}
			}

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				if (userId != null) {
					qPos.add(userId);
				}

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
					finderArgs, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Counts all the bank_ payment_ slips.
	 *
	 * @return the number of bank_ payment_ slips
	 * @throws SystemException if a system exception occurred
	 */
	public int countAll() throws SystemException {
		Object[] finderArgs = new Object[0];

		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
				finderArgs, this);

		if (count == null) {
			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(_SQL_COUNT_BANK_PAYMENT_SLIP);

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
					count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Initializes the bank_ payment_ slip persistence.
	 */
	public void afterPropertiesSet() {
		String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
					com.liferay.util.service.ServiceProps.get(
						"value.object.listener.com.crossriver.crgis.database.model.Bank_Payment_Slip")));

		if (listenerClassNames.length > 0) {
			try {
				List<ModelListener<Bank_Payment_Slip>> listenersList = new ArrayList<ModelListener<Bank_Payment_Slip>>();

				for (String listenerClassName : listenerClassNames) {
					listenersList.add((ModelListener<Bank_Payment_Slip>)InstanceFactory.newInstance(
							listenerClassName));
				}

				listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
			}
			catch (Exception e) {
				_log.error(e);
			}
		}
	}

	public void destroy() {
		EntityCacheUtil.removeCache(Bank_Payment_SlipImpl.class.getName());
		FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
		FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
	}

	@BeanReference(type = Application_C_of_OPersistence.class)
	protected Application_C_of_OPersistence application_C_of_OPersistence;
	@BeanReference(type = Supporting_DocumentPersistence.class)
	protected Supporting_DocumentPersistence supporting_DocumentPersistence;
	@BeanReference(type = DocumentsPersistence.class)
	protected DocumentsPersistence documentsPersistence;
	@BeanReference(type = Individual_InformationPersistence.class)
	protected Individual_InformationPersistence individual_InformationPersistence;
	@BeanReference(type = Organisation_InformationPersistence.class)
	protected Organisation_InformationPersistence organisation_InformationPersistence;
	@BeanReference(type = Contact_InformationPersistence.class)
	protected Contact_InformationPersistence contact_InformationPersistence;
	@BeanReference(type = Company_Contact_PersonPersistence.class)
	protected Company_Contact_PersonPersistence company_Contact_PersonPersistence;
	@BeanReference(type = Property_InformationPersistence.class)
	protected Property_InformationPersistence property_InformationPersistence;
	@BeanReference(type = Held_PlotsPersistence.class)
	protected Held_PlotsPersistence held_PlotsPersistence;
	@BeanReference(type = History_Of_InformationPersistence.class)
	protected History_Of_InformationPersistence history_Of_InformationPersistence;
	@BeanReference(type = TransactionsPersistence.class)
	protected TransactionsPersistence transactionsPersistence;
	@BeanReference(type = Bank_Payment_SlipPersistence.class)
	protected Bank_Payment_SlipPersistence bank_Payment_SlipPersistence;
	@BeanReference(type = ResourcePersistence.class)
	protected ResourcePersistence resourcePersistence;
	@BeanReference(type = UserPersistence.class)
	protected UserPersistence userPersistence;
	private static final String _SQL_SELECT_BANK_PAYMENT_SLIP = "SELECT bank_Payment_Slip FROM Bank_Payment_Slip bank_Payment_Slip";
	private static final String _SQL_SELECT_BANK_PAYMENT_SLIP_WHERE = "SELECT bank_Payment_Slip FROM Bank_Payment_Slip bank_Payment_Slip WHERE ";
	private static final String _SQL_COUNT_BANK_PAYMENT_SLIP = "SELECT COUNT(bank_Payment_Slip) FROM Bank_Payment_Slip bank_Payment_Slip";
	private static final String _SQL_COUNT_BANK_PAYMENT_SLIP_WHERE = "SELECT COUNT(bank_Payment_Slip) FROM Bank_Payment_Slip bank_Payment_Slip WHERE ";
	private static final String _FINDER_COLUMN_APPLICATIONID_APPLICATIONID_1 = "bank_Payment_Slip.applicationId IS NULL";
	private static final String _FINDER_COLUMN_APPLICATIONID_APPLICATIONID_2 = "bank_Payment_Slip.applicationId = ?";
	private static final String _FINDER_COLUMN_APPLICATIONID_APPLICATIONID_3 = "(bank_Payment_Slip.applicationId IS NULL OR bank_Payment_Slip.applicationId = ?)";
	private static final String _FINDER_COLUMN_USERID_USERID_1 = "bank_Payment_Slip.userId IS NULL";
	private static final String _FINDER_COLUMN_USERID_USERID_2 = "bank_Payment_Slip.userId = ?";
	private static final String _FINDER_COLUMN_USERID_USERID_3 = "(bank_Payment_Slip.userId IS NULL OR bank_Payment_Slip.userId = ?)";
	private static final String _ORDER_BY_ENTITY_ALIAS = "bank_Payment_Slip.";
	private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Bank_Payment_Slip exists with the primary key ";
	private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Bank_Payment_Slip exists with the key {";
	private static Log _log = LogFactoryUtil.getLog(Bank_Payment_SlipPersistenceImpl.class);
}